﻿// =============================================================================
// XPathDebugger And Examples TradeCashFlow.cs
// Copyright (c) 2013 TNTTechnologies Inc.
// =============================================================================

#region

using System;
using System.Collections.Generic;

#endregion

namespace Example{
    /// <summary>
    ///     Holds a list of cashflows and a market data date
    ///     which will be used to generate the aggrigated cash flow report
    /// </summary>
    public class TradeCashFlows{
        private List<TradeCashFlow> tradeCashFlowList = new List<TradeCashFlow>();
        public DateTime MarketDataDate { get; set; }

        public List<TradeCashFlow> TradeCashFlowList{
            get{
                return this.tradeCashFlowList;
            }
            set{
                this.tradeCashFlowList = value;
            }
        }

        public void FilterByPaymentDateRange(DateTime valuationDate, DateTime cashflowEndDate){
            List<TradeCashFlow> tempListCashFlows = new List<TradeCashFlow>();

            for (int i = 0; i < this.tradeCashFlowList.Count; ++i){
                if (this.tradeCashFlowList[i].IsInPaymentDateRange(ref valuationDate, ref cashflowEndDate)){
                    tempListCashFlows.Add(this.tradeCashFlowList[i]);
                }
            }
            this.tradeCashFlowList = tempListCashFlows;
        }
    }

    /// <summary>
    ///     Used to store the return values from the metric level of the trade
    ///     which will be used to generate the aggrigated cash flow report
    /// </summary>
    public class TradeCashFlow{
        public DateTime PaymentDate { get; set; }
        public double CashFlow { get; set; }
        public double PresentValueCashFlow { get; set; }

        public bool IsInPaymentDateRange(ref DateTime begin, ref DateTime end){
            if (this.PaymentDate >= begin && (this.PaymentDate <= end)){
                return true;
            }
            return false;
        }
    }
}